package com.linyaonan.leetcode.easy._55;

class Solution {

    public static int max = 0;

    public int maxDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        getDep(root, 1);
        return max;
    }

    private void getDep(TreeNode root, int lastCount) {
        if (root != null) {
            max = Math.max(max, lastCount);
            getDep(root.left, ++lastCount);
            --lastCount;
            getDep(root.right, ++lastCount);
            --lastCount;
        }
    }
}